<?php
// +-------------------------------------------------------------------
// |
// +-------------------------------------------------------------------
// | Copyright (c) 2009-2016 All rights reserved.
// +-------------------------------------------------------------------
namespace Service\Api\V1;

use Think\Model;

class NewsDetail
{
    public $login = false; //是否需要登录才能访问该接口
    public $title = "政务资讯详情ok";
    public $group = '政务资讯';
    public $desc = "";

    public $input = [
        'id' => 'required;int;label=租赁合同id;',
    ];

    public $output = [
        [
            'id' => 'label=id;',
            'title' => 'label=标题;',
            'logo_img' => 'label=logo图;',
            'content' => 'label=内容(富文本);',
            'create_time' => 'label=创建时间;',
            'is_collect' => 'label=收藏状态： 0未收藏 1已收藏;',
        ]
    ];

    public function run($param, $uid)
    {

        $list = M('news')->where(['id' => $param['id']])->find();
        if(!$list) throw new \Exception('未找到该资讯');
        $collect =  M('user_collect')->where(['relate_id' => $param['id'], 'type' => 2])
            ->find();
        if($collect){
            $list['is_collect'] = 1;
        }else{
            $list['is_collect'] = 0;
        }
        return $list;
    }
}
